package com.lemon.blog.system.controller;

import com.lemon.blog.system.domain.BlMusic;
import com.lemon.blog.system.service.IBlMusicService;
import com.lemon.common.core.web.controller.BaseController;
import com.lemon.common.core.web.domain.AjaxResult;
import com.lemon.common.core.web.page.TableDataInfo;
import com.lemon.common.log.annotation.Log;
import com.lemon.common.log.enums.BusinessType;
import com.lemon.common.security.utils.ExcelUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import com.lemon.common.security.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 包名称：com.lemon.blog.controller
 * 类名称：BlMusicController
 * 类描述：音乐欣赏Controller
 * 创建人：@author huangpeng
 * 创建时间：2022-05-04
 */
@Api("音乐管理")
@RestController
@RequestMapping("/music")
public class BlMusicController extends BaseController
{
    @Autowired
    private IBlMusicService blMusicService;

    /**
     * 查询音乐欣赏列表
     * @Title: list
     * @Description: 查询音乐欣赏列表
     * @param blMusic 音乐欣赏
     * @return: TableDataInfo
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:music:list")
    @GetMapping("/list")
    public TableDataInfo list(BlMusic blMusic)
    {
        startPage();
        List<BlMusic> list = blMusicService.selectBlMusicList(blMusic);
        return getDataTable(list);
    }

    /**
     * 导出音乐欣赏列表
     * @Title: export
     * @Description: 导出音乐欣赏列表
     * @param response response
     * @param blMusic 音乐欣赏
     * @return:
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:music:export")
    @Log(title = "音乐欣赏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlMusic blMusic)
    {
        List<BlMusic> list = blMusicService.selectBlMusicList(blMusic);
        ExcelUtil<BlMusic> util = new ExcelUtil<BlMusic>(BlMusic.class);
        util.exportExcel(response, list, "音乐欣赏数据");
    }

    /**
     * 获取音乐欣赏详细信息
     * @Title: getInfo
     * @Description: 获取音乐欣赏详细信息
     * @param id 音乐欣赏主键
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:music:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(blMusicService.selectByPrimaryKey(id));
    }

    /**
     * 新增音乐欣赏
     * @Title: add
     * @Description: 新增音乐欣赏
     * @param blMusic 音乐欣赏
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:music:add")
    @Log(title = "音乐欣赏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlMusic blMusic)
    {
        return toAjax(blMusicService.insert(blMusic));
    }

    /**
     * 修改音乐欣赏
     * @Title: edit
     * @Description: 修改音乐欣赏
     * @param blMusic 音乐欣赏
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:music:edit")
    @Log(title = "音乐欣赏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlMusic blMusic)
    {
        return toAjax(blMusicService.update(blMusic));
    }

    /**
     * 删除音乐欣赏
     * @Title: remove
     * @Description: 删除音乐欣赏
     * @param ids 需要删除的音乐欣赏主键集合
     * @return: AjaxResult
     * @throws:
     * @author: huangpeng
     * @Date: 2022-05-04
     */
    @RequiresPermissions("blog:music:remove")
    @Log(title = "音乐欣赏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blMusicService.deleteByBatch(ids));
    }
}
